<?php
require_once '../sub/init.php';
header("Cache-control: private");
require_once 'chkUadm.php';
require_once ZEAI.'cache/config_crm.php';
require_once ZEAI.'sub/ZeaiUP.php';
if(!CRMQX('crm_talk_gj')){exit(noauth('暂无【外呼客户跟进】权限'));}
if(!CRMQX('crm_talk_gj_add') && ($submitok=='add' || $submitok=='add_update')){exit(noauth('暂无【外呼客户跟进(增加)】权限'));}
if(!CRMQX('crm_talk_gj_mod') && ($submitok=='mod' || $submitok=='mod_update')){exit(noauth('暂无【外呼客户跟进(修改)】权限'));}
if(!CRMQX('crm_talk_gj_del') && $submitok=='alldel'){exit(noauth('暂无【外呼客户跟进(删除)】权限'));}
function show_his($num){
	if($num>0){
		$tj_zd=intval($num);
		$whs_h=floor($num/3600);	
		$whs_i=floor(($num-$whs_h*3600)/60);	
		$whs_s=$num-$whs_h*3600-$whs_i*60;	
	}else{
		return '0秒';
	}
	$times_str='';
	if($whs_h>0){$times_str.=$whs_h.'时';}
	if($whs_i>0 || $whs_h>0){$times_str.=$whs_i.'分';}
	if($whs_s>0 || $whs_i>0 || $wh_h>0){$times_str.=$whs_s.'秒';}
	if(empty($times_str))$times_str='0秒';
	return $times_str;
}
if($submitok=='add_update'){	
	if(!ifint($session_uid))json_exit(array('flag'=>0,'msg'=>'获取操作员ID失败，请重新登录后再试'));
	if(!ifint($wh_uid))json_exit(array('flag'=>0,'msg'=>'获取客户uid失败，请重试'));
	
	$SQL = "  (flag=1 OR flag=-2) AND kind<>4 AND admid>0 AND crm_ugrade=0 ";
	if(!CRM_ADM)$SQL .= " AND (admid=".$session_uid." OR hnid=".$session_uid." OR hnid2=".$session_uid.") ";//我的
	$SQL .= " AND id=".$wh_uid;
	if(!$db->ROW(__TBL_USER__,"id",$SQL))json_exit(array('flag'=>0,'msg'=>'此客户不是【您的客户】或【售前客户】'));
	
	if (!$db->ROW(__TBL_USER__,"id","id=".$wh_uid))json_exit(array('flag'=>0,'msg'=>'此用户不存在，请检查'));
	$sql_k="agentid,agenttitle,admid,admname,uid";$sql_v="$session_agentid,'$session_agenttitle','$session_uid','$session_truename','$wh_uid'";
	$wh_name = dataIO(TrimEnter($wh_name),'in');
	if (str_len($wh_name)<2 || str_len($wh_name) >8)json_exit(array('flag'=>0,'msg'=>'请输入正确的客户姓名'));		
	$sql_k .= ",name";	$sql_v .= ",'$wh_name'";	
	$wh_mob = dataIO(TrimEnter($wh_mob),'in');
	if (str_len($wh_mob) >12 || str_len($wh_mob) <11)json_exit(array('flag'=>0,'msg'=>'请输入正确的电话号码手机号码11位，固定电话12位'));	
	$sql_k .= ",mob";	$sql_v .= ",'$wh_mob'";	
	if(!ifint($wh_flag) || $wh_flag<1 || $wh_flag>5){json_exit(array('flag'=>0,'msg'=>'请设置外呼状态'));}	
	$sql_k .= ",flag";	$sql_v .= ",'$wh_flag'";	
	if($wh_flag==4){
		if(!ifint($wh_h))$wh_h=0;if(!ifint($wh_i))$wh_i=0;if(!ifint($wh_s))$wh_s=0;		
		if($wh_h<1 && $wh_i<1 && $wh_s<1){ json_exit(array('flag'=>0,'msg'=>'请设置外呼通话')); }		
		$talktime=intval($wh_h)*3600+intval($wh_i)*60+intval($wh_s);
		if($talktime<1){ json_exit(array('flag'=>0,'msg'=>'请设置外呼通话')); }	
		$sql_k .= ",talktime";	$sql_v .= ",'$talktime'";
	}
	if(!empty($wh_content)){
		$bz = dataIO(TrimEnter($wh_content),'in');
		if (str_len($bz) > 200)json_exit(array('flag'=>0,'msg'=>'备注字太多不要超过200字节'));
		$sql_k .= ",talkbz";$sql_v .= ",'$bz'";
	}	
	//查询是否存在记录 根据admid，查询当前1小时内是存在记录
	/*
	$row = $db->ROW(__TBL_TALK__,"id,admid,addtime","addtime <= DATE_SUB(NOW(),INTERVAL 1 HOUR) AND uid=".$wh_uid,'name');//
	if($row){
		if($row['admid']!=$session_uid){
			json_exit(array('flag'=>0,'msg'=>'您的同事已记录过该客户外呼信息，请确认您录入的信息是否正确或1小时后再提交'));
		}else{
			json_exit(array('flag'=>0,'msg'=>'您已记录过该客户外呼信息，请勿重复录入或1小时后再提交'));
		}
	}
	*/
	$db->query("INSERT INTO ".__TBL_TALK__." (".$sql_k.") VALUES (".$sql_v.")");
	sea_mod_time($wh_uid);
	AddLog('【外呼跟进】->增加【客户：uid:'.$wh_uid.'|'.$wh_name.'|'.$wh_mob.'】');
	json_exit(array('flag'=>1,'msg'=>'录入成功'));
	
}elseif($submitok == "mod_update"){	
	if(!ifint($wh_id))json_exit(array('flag'=>0,'msg'=>'获取操作记录ID失败，请重试'));
	if(!ifint($wh_uid))json_exit(array('flag'=>0,'msg'=>'获取会员ID失败，请重试'));
	if(!ifint($session_uid))json_exit(array('flag'=>0,'msg'=>'获取操作员ID失败，请重新登录后再试'));
	$wh_name = dataIO(TrimEnter($wh_name),'in');
	if (str_len($wh_name)<2 || str_len($wh_name) >8)json_exit(array('flag'=>0,'msg'=>'请输入正确的客户姓名'));		
	$sql_k .= "uid='$wh_uid',name='$wh_name'";	
	$wh_mob = dataIO(TrimEnter($wh_mob),'in');
	if (str_len($wh_mob) >12 || str_len($wh_mob) <11)json_exit(array('flag'=>0,'msg'=>'请输入正确的电话号码手机号码11位，固定电话12位'));	
	$sql_k .= ",mob='$wh_mob'";	
	if(!ifint($wh_flag) || $wh_flag<1 || $wh_flag>5){json_exit(array('flag'=>0,'msg'=>'请设置外呼状态'));}	
	$sql_k .= ",flag='$wh_flag'";	
	if($wh_flag==4){
		if(!ifint($wh_h))$wh_h=0;if(!ifint($wh_i))$wh_i=0;if(!ifint($wh_s))$wh_s=0;		
		if($wh_h<1 && $wh_i<1 && $wh_s<1){ json_exit(array('flag'=>0,'msg'=>'请设置外呼通话')); }		
		$talktime=intval($wh_h)*3600+intval($wh_i)*60+intval($wh_s);
		if($talktime<1){ json_exit(array('flag'=>0,'msg'=>'请设置外呼通话')); }	
		$sql_k .= ",talktime='$talktime'";
	}
	if(!empty($wh_content)){
		$bz = dataIO(TrimEnter($wh_content),'in');
		if (str_len($bz) > 200)json_exit(array('flag'=>0,'msg'=>'备注字太多不要超过200字节'));
		$sql_k .= ",talkbz='$bz'";
	}
	$db->query("UPDATE ".__TBL_TALK__." SET ".$sql_k." WHERE id=".$wh_id);
	AddLog('【外呼跟进】->修改【ID：'.$wh_id.'|客户'.$wh_name.'|'.$wh_mob.'】');
	json_exit(array('flag'=>1,'msg'=>'操作成功'));	
}elseif($submitok == "alldel"){		
	$tmeplist = $list;
	if(empty($tmeplist))json_exit(array('flag'=>0,'msg'=>'请选择您要删除的信息'));
	if(!is_array($tmeplist))exit(JSON_ERROR);
	if(count($tmeplist)>=1){
		if(!CRM_ADM)$SQL = " AND admid=".$session_uid;
		foreach($tmeplist as $value){$v=intval($value);
			$db->query("DELETE FROM ".__TBL_TALK__." WHERE id=".$v.$SQL);
			AddLog('【外呼跟进】->删除【ID：'.$v.'（id:'.$session_uid.'）】');			
		}
	}
	json_exit(array('flag'=>1,'msg'=>'删除成功'));
}
if(CRM_ADM){
	$SQL="flag>0";
	$Skey  = trimhtml($Skey);
	if (ifint($Skey)){
		$SQL .= " AND admid=$Skey ";
	}elseif(!empty($Skey)){
		$SQL .= " AND (admname LIKE '%".$Skey."%')";
	}
}else{
	$SQL="admid=".$session_uid;
}
//超管搜索按门店
if (ifint($agentid) && CRM_ADM)$SQL .= " AND agentid=$agentid";

if(ifint($uid)){
	$urow= $db->ROW(__TBL_USER__,"id,truename,nickname,mob","id=".$uid,'name');
}
if (ifint($qxflag) && $qxflag>0){$SQL .= " AND flag = $qxflag ";}else{$qxflag=0;}
$Skey2 = trimhtml($Skey2);
if(!empty($Skey2)){
	if(ifmob($Skey2)){
		$SQL .= " AND ( mob= '".$Skey2."')";
	}elseif(ifint($Skey2)){
		$SQL .= " AND (  uid = '".$Skey2."')";
	}else{
		$SQL .= " AND (  name LIKE '%".$Skey2."%' or mob like '%".$Skey2."%' )";
	}
}

if(!empty($sDATE1)){
	$sDATE1 = $sDATE1.' 00:00:00';
	$SQL .= " AND ( addtime >= '$sDATE1' )";		
}
if(!empty($sDATE2)){
	$sDATE2 = $sDATE2.' 23:59:59';
	$SQL .= " AND ( addtime <= '$sDATE2' )";
}
$tj_sql=$SQL;
switch ($sort) {
	default:$SORT = " ORDER BY id DESC ";break;
}
$rt = $db->query("SELECT * FROM ".__TBL_TALK__." WHERE ".$SQL." ".$SORT." LIMIT ".$_ADM['admLimit']);
$total = $db->num_rows($rt);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/cache/udata.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/res/select4.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script>qxflag_ARR=<?php echo $_CRM['qxflag'];?>;</script>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
<link href="css/crm.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
</head>
<style>
td.border0{vertical-align:top;padding-top:10px;line-height:12px}
img.photo_s{width:60px;height:60px;display:block;margin:12px auto;border-radius:40px;object-fit:cover;-webkit-object-fit:cover;cursor:zoom-in}
.pathlist img{margin:8px 5px 5px 2px;width:30px;height:30px;object-fit:cover;-webkit-object-fit:cover;border-radius:2px}
.box{padding-top:10px;padding-bottom:20px;min-width:1200px}
.top4,.top4 li,.top4,.top4 li i{box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}
.top4{width:100%;min-width:1200px;padding:0 15px;margin-top:20px}
.top4 li{width:25%;float:left;width:calc(25% - 20px);width:-webkit-calc(25% - 20px);margin-right:20px;min-width:250px;height:91px;padding:10px;background-color:#fff;position:relative;color:#999;border-radius:4px}
.top4 li:last-child{width:25%;margin-right:0}
.top4 li i{position:absolute;left:15px;top:15px;width:60px;border-radius:30px;height:60px;font-size:30px;line-height:60px;color:#fff;background-color:#009688/*border:1px solid #FF5722*/}
.top4 li em{font-size:13px;padding-left:80px;text-align:left;padding-top:8px}
.top4 li em b{display:inline-block;font-weight:bold;font-size:26px;color:#009688;font-family:Arial}
.top4 li em font.hot{font-size:13px;color:#EE5A4E}
.top4 li .liRnum{font-size:13px;color:#666;margin-left:10px;display:inline-block}
.top4 li .liRnum b{font-size:16px;color:#009688;margin:0 5px;}
.top4 li .liRnum b,.top4 li .liRnum font{vertical-align:middle}
</style>
<body <?php if ($submitok == 'add' || $submitok == 'mod'){?>class='body'<?php }?>>
<?php
if ($submitok == 'add'){?>
<form id="wh_GYLform">
    <table class="table W95_ Mtop20" style="margin:15px 0 0 15px">
    <tr>
      <td class="tdL"><font class="Cf00">*</font>客户UID</td>
      <td class="tdR"><input id="wh_uid" name="wh_uid" type="text" maxlength="25" class="input size2 W200" placeholder="客户UID" value="<?php echo $uid;?>">
      </td>
    </tr>
    <tr>
      <td class="tdL"><font class="Cf00">*</font>客户姓名</td>
      <td class="tdR"><input id="wh_name" name="wh_name" type="text" maxlength="25" class="input size2 W200" placeholder="客户姓名" value="<?php echo dataIO($urow['truename'],'out');?>">
      </td>
    </tr>
    <tr>
      <td class="tdL"><font class="Cf00">*</font>客户电话</td>
      <td class="tdR"><input id="wh_mob" name="wh_mob" type="text" maxlength="25" class="input size2 W200" placeholder="客户电话" value="<?php echo $urow['mob'];?>">
      </td>
    </tr>
    <tr>
      <td class="tdL"><font class="Cf00">*</font>外呼状态</td>
      <td class="tdR">
      	<input type="radio" name="wh_flag0" value="4" id="flag4" class="radioskin"><label for="flag4" class="radioskin-label" onClick="set_flag_all(4)"><i class="i1"></i><b class="W75">成功接通</b></label>
        <input type="radio" name="wh_flag0" value="3" id="flag3" class="radioskin"><label for="flag3" class="radioskin-label" onClick="set_flag_all(3)"><i class="i1"></i><b class="W75">客户拒接</b></label>
        <input type="radio" name="wh_flag0" value="2" id="flag2" class="radioskin"><label for="flag2" class="radioskin-label" onClick="set_flag_all(2)"><i class="i1"></i><b class="W75">无人接听</b></label>
        <input type="radio" name="wh_flag0" value="1" id="flag1" class="radioskin"><label for="flag1" class="radioskin-label" onClick="set_flag_all(1)"><i class="i1"></i><b class="W75">空号错号</b></label>                
        <input type="radio" name="wh_flag0" value="5" id="flag5" class="radioskin"><label for="flag5" class="radioskin-label" onClick="set_flag_all(5)"><i class="i1"></i><b class="W50">其它</b></label>
      </td>
    </tr>
    <tr id="thtime" style="display:none;">
      <td class="tdL"><font class="Cf00">*</font>通话时长</td>
      <td class="tdR"><input id="wh_h" name="wh_h" type="tel" maxlength="5" class="input size2 W50" placeholder="时" value="0"> 时 <input id="wh_i" name="wh_i" type="tel" maxlength="2" class="input size2 W50" placeholder="分" value="0"> 分 <input id="wh_s" name="wh_s" type="tel" maxlength="2" class="input size2 W50" placeholder="秒" value="0"> 秒
      </td>
    </tr>
    <tr>
      <td class="tdL">备注说明</td>
      <td class="tdR"><textarea id="wh_content" name="wh_content" rows="4" class="textarea W100_" placeholder="请输入本次外呼通话相关备注说明"><?php echo $bz;?></textarea>
      </td>
    </tr>
    </table>
    <input type="hidden" name="submitok" value="add_update" />
    <input type="hidden" id="wh_flag" name="wh_flag" value="0" />
    <div class="savebtnbox"><button type="button" class="btn size3" id="save">提交保存</button></div>
	</form>
    <script>
    function set_flag_all(vid){
		if(vid==4){
			document.getElementById("thtime").style.display="";
		}else{
			document.getElementById("thtime").style.display="none";
		}
		document.getElementById("wh_flag").value=vid;
	} 
	var up2='<?php echo $_ZEAI['up2'];?>/',upMaxMB=<?php echo $_UP['upMaxMB']; ?>;
	save.onclick=function(){
		if (zeai.empty(o('wh_name').value)){
			zeai.msg('请输入【客户姓名】',o('wh_name'));	
			return false;
		}
		if (zeai.empty(o('wh_mob').value)){
			zeai.msg('请输入【客户电话】',o('wh_mob'));	
			return false;
		}
		if (zeai.empty(o('wh_flag').value) || parseInt(o('wh_flag').value)<1 || parseInt(o('wh_flag').value)>5){
			zeai.msg('请设置【外呼状态】');	
			return false;
		}
		if(parseInt(o('wh_flag').value)==4){
			if( parseInt(o('wh_h').value)<1 && parseInt(o('wh_i').value)<1 && parseInt(o('wh_s').value)<1){
				zeai.msg('请设置【通话时长】');	
				return false;
			}			
		}
		if (!zeai.empty(o('wh_content').value)){
			var wh_content_str=o('wh_content').value;
			if(wh_content_str.length>200){
				zeai.msg('【备注说明】请保持在200个字符以内');	
				return false;
			}
		}		
		//zeai.confirm('确定要提交么？提交后无法修改，请确认！',function(){
			zeai.ajax({url:'crm_talk_gj'+zeai.extname,form:wh_GYLform},function(e){var rs=zeai.jsoneval(e);
				window.parent.zeai.msg(0);window.parent.zeai.msg(rs.msg);
				if(rs.flag==1){setTimeout(function(){window.parent.location.reload(true);parent.zeai.iframe(0);},1000);}
			});
		//});
	}
    </script>
	<?php
    exit;
}elseif ($submitok == 'mod'){
	if(!ifint($id))alert_adm("【外呼跟进】获取记录ID失败，请重试！",SELF);
	$mod_row = $db->ROW(__TBL_TALK__,"*","id=".$id,'name');
	$flag=$mod_row['flag'];
	$uid=$mod_row['uid'];
	$talkbz=dataIO($mod_row['talkbz'],'out');
	$wh_h=0;	
	$wh_i=0;	
	$wh_s=0;
	if($mod_row['talktime']>0){
		$wh_h=floor($mod_row['talktime']/3600);	
		$wh_i=floor(($mod_row['talktime']-$wh_h*3600)/60);	
		$wh_s=$mod_row['talktime']-$wh_h*3600-$wh_i*60;	
	}?>
<form id="wh_GYLform">
    <table class="table W95_ Mtop20" style="margin:15px 0 0 15px">
    <tr>
      <td class="tdL"><font class="Cf00">*</font>客户UID</td>
      <td class="tdR"><input id="wh_uid" name="wh_uid" type="text" maxlength="25" class="input size2 W200" placeholder="客户UID" value="<?php echo $uid;?>">
      </td>
    </tr>
    <tr>
      <td class="tdL"><font class="Cf00">*</font>客户姓名</td>
      <td class="tdR"><input id="wh_name" name="wh_name" type="text" maxlength="25" class="input size2 W200" placeholder="客户姓名" value="<?php echo $mod_row['name'];?>">
      </td>
    </tr>
    <tr>
      <td class="tdL"><font class="Cf00">*</font>客户电话</td>
      <td class="tdR"><input id="wh_mob" name="wh_mob" type="text" maxlength="25" class="input size2 W200" placeholder="客户电话" value="<?php echo $mod_row['mob'];?>">
      </td>
    </tr>
    <tr>
      <td class="tdL"><font class="Cf00">*</font>外呼状态</td>
      <td class="tdR">
      <input type="radio" name="wh_flag0" value="4" id="flag4" class="radioskin"<?php echo ($flag == 4)?' checked':'';?>><label for="flag4" class="radioskin-label" onClick="set_flag_all(4)"><i class="i1"></i><b class="W75">成功接通</b></label>
      <input type="radio" name="wh_flag0" value="3" id="flag3" class="radioskin"<?php echo ($flag == 3)?' checked':'';?>><label for="flag3" class="radioskin-label" onClick="set_flag_all(3)"><i class="i1"></i><b class="W75">客户拒接</b></label>
        <input type="radio" name="wh_flag0" value="2" id="flag2" class="radioskin"<?php echo ($flag == 2)?' checked':'';?>><label for="flag2" class="radioskin-label" onClick="set_flag_all(2)"><i class="i1"></i><b class="W75">无人接听</b></label>
        
        <input type="radio" name="wh_flag0" value="1" id="flag1" class="radioskin"<?php echo ($flag == 1)?' checked':'';?>><label for="flag1" class="radioskin-label" onClick="set_flag_all(1)"><i class="i1"></i><b class="W75">空号错号</b></label>
        <input type="radio" name="wh_flag0" value="5" id="flag5" class="radioskin"<?php echo ($flag == 5)?' checked':'';?>><label for="flag5" class="radioskin-label" onClick="set_flag_all(5)"><i class="i1"></i><b class="W50">其它</b></label>      
      </td>
    </tr>
    <tr id="thtime" style="<?php if($flag!=4){ echo 'display:none;';}?>">
      <td class="tdL"><font class="Cf00">*</font>通话时长</td>
      <td class="tdR"><input id="wh_h" name="wh_h" type="tel" maxlength="5" class="input size2 W50" placeholder="时" value="<?php echo $wh_h;?>"> 时 <input id="wh_i" name="wh_i" type="tel" maxlength="2" class="input size2 W50" placeholder="分" value="<?php echo $wh_i;?>"> 分 <input id="wh_s" name="wh_s" type="tel" maxlength="2" class="input size2 W50" placeholder="秒" value="<?php echo $wh_s;?>"> 秒
      </td>
    </tr>
    <tr>
      <td class="tdL">备注说明</td>
      <td class="tdR"><textarea id="wh_content" name="wh_content" rows="4" class="textarea W100_" placeholder="请输入本次外呼通话相关备注说明"><?php echo $talkbz;?></textarea>
      </td>
    </tr>
    </table>
    <input type="hidden" name="submitok" value="mod_update" />
    <input type="hidden" id="wh_flag" name="wh_flag" value="<?php echo $flag;?>" />
    <input type="hidden" id="wh_id" name="wh_id" value="<?php echo $id;?>" />
    <div class="savebtnbox"><button type="button" class="btn size3" id="save">提交保存</button></div>
	</form>
    <script>
    function set_flag_all(vid){
		if(vid==4){
			document.getElementById("thtime").style.display="";
		}else{
			document.getElementById("thtime").style.display="none";
		}
		document.getElementById("wh_flag").value=vid;
	} 
	var up2='<?php echo $_ZEAI['up2'];?>/',upMaxMB=<?php echo $_UP['upMaxMB']; ?>;
	save.onclick=function(){
		if (zeai.empty(o('wh_name').value)){
			zeai.msg('请输入【客户姓名】',o('wh_name'));	
			return false;
		}
		if (zeai.empty(o('wh_mob').value)){
			zeai.msg('请输入【客户电话】',o('wh_mob'));	
			return false;
		}
		if (zeai.empty(o('wh_flag').value) || parseInt(o('wh_flag').value)<1 || parseInt(o('wh_flag').value)>5){
			zeai.msg('请设置【外呼状态】');	
			return false;
		}
		if(parseInt(o('wh_flag').value)==4){
			if( parseInt(o('wh_h').value)<1 && parseInt(o('wh_i').value)<1 && parseInt(o('wh_s').value)<1){
				zeai.msg('请设置【通话时长】');	
				return false;
			}			
		}
		if (!zeai.empty(o('wh_content').value)){
			var wh_content_str=o('wh_content').value;
			if(wh_content_str.length>200){
				zeai.msg('【备注说明】请保持在200个字符以内');	
				return false;
			}
		}		
		//zeai.confirm('确定要提交么？提交后无法修改，请确认！',function(){
			zeai.ajax({url:'crm_talk_gj'+zeai.extname,form:wh_GYLform},function(e){var rs=zeai.jsoneval(e);
				window.parent.zeai.msg(0);window.parent.zeai.msg(rs.msg);
				if(rs.flag==1){setTimeout(function(){window.parent.location.reload(true);parent.zeai.iframe(0);},1000);}
			});
		//});
	}
    </script>
	<?php
	exit;
}
?>
<div class="top4">
	<li>
	<i class="ico">总</i>
	<em>
        <b><?php $tj_za=$db->COUNT(__TBL_TALK__,$tj_sql); echo $tj_za;?></b> 次</font>
        <span><br><font class="h6b">总呼出数</font>(次)
        </span>
	</em>
    </li>
	<li>
    	<i class="ico">接</i>
		<em>
			<b><?php $tj_zb=$db->COUNT(__TBL_TALK__,$tj_sql.' AND flag=4');echo $tj_zb;?></b> 次
            <span><br><font class="h6b">接通数</font>（次）</span>
        </em>
    </li>
	
	<li>
    	<i class="ico">效</i>
		<em>
			<b><?php 
			$tj_zc = $db->COUNT(__TBL_TALK__,$tj_sql.' AND flag=4 AND talktime>30','name');			
			echo $tj_zc;?></b> 次
            <span><br><font class="h6b">有效数</font>（30秒）</span>
        </em>
    </li>    
    <li>
    	<i class="ico">时</i>
		<em>
			<b><?php 
			$tj_zd=0;
			$cxrow = $db->ROW(__TBL_TALK__,"sum(talktime) AS ztalktime",$tj_sql." AND flag=4",'name');			
			$tj_zd=intval($cxrow['ztalktime']);
			echo show_his($tj_zd);		 		
			?></b>
            <span><br><font class="h6b">总时长</font></span>(秒)
        </em>
    </li>
</div>
<div class="clear"></div>
<div class="top4" style="margin-top:15px">
    <li>
    	<i class="ico">通</i>
		<em>
			<b><?php echo ($tj_za>0)?sprintf("%.2f",($tj_zb*100/$tj_za)):'0.00';?></b> %
            <span><br><font class="h6b">接通率</font>（%）</span>
        </em>
    </li>
    <li>
    	<i class="ico">有</i>
		<em>
			<b><?php echo ($tj_zb>0)?sprintf("%.2f",($tj_zc*100/$tj_zb)):'0.00';?></b> %
            <span><br><font class="h6b">有效接通率</font>（30秒）</span>
        </em>
    </li>    
    <li>
    	<i class="ico">均</i>
		<em>
			<b><?php echo ($tj_za>0)?show_his(intval($tj_zd/$tj_za)):'0秒';?></b>
            <span><br><font class="h6b">平均时长</font>（秒）</span>
        </em>
    </li>
    <li>
    	<i class="ico">今</i>
		<em>
			<b><?php $tj_ze = $db->COUNT(__TBL_TALK__,$tj_sql.' AND TO_DAYS(addtime) = TO_DAYS(NOW())','name');	
				echo $tj_ze;			
			?></b> 次
            <span><br><font class="h6b">今日外呼总数</font>（次）</span>
        </em>
    </li>
</div>
<div class="clear"></div>

<div class="box">
    <div class="topsearch">
		<?php if(CRMQX('crm_talk_gj_add')){?>
         <button type="button" class="btn size2" title2="添加外呼记录"  onClick="zeai.iframe('新增外呼记录','crm_talk_gj.php?submitok=add',700,430);return false"><i class="ico">&#xe622;</i> 新增外呼记录</button>　　　<?php }?>
        <form name="ZEAI_CN__form1" method="get" action="<?php echo SELF; ?>" style="margin-right:20px">
          <!--超管按门店查询-->
          <?php if(CRM_ADM){?>
          <?php
            $rt2=$db->query("SELECT id,title FROM ".__TBL_CRM_AGENT__." WHERE flag=1 ORDER BY px DESC,id DESC");
            $total2 = $db->num_rows($rt2);
            if ($total2 > 0) {?>
                <select name="agentid" class="W150 size2 picmiddle">
                <option value="">不限门店</option>
				<?php
                for($j=0;$j<$total2;$j++) {
                    $rows2 = $db->fetch_array($rt2,'num');
                    if(!$rows2) break;
                    $clss=($agentid==$rows2[0])?' selected':'';?><option value="<?php echo $rows2[0];?>"<?php echo $clss;?>><?php echo dataIO($rows2[1],'out');?></option><?php
                }?>
                </select>　<?php
            }?>
			<input name="Skey" type="text" maxlength="25" class="input size2 W200" placeholder="按红娘ID号和姓名" value="<?php echo $Skey; ?>">　
			<?php }?>
          <!---->
        <input name="Skey2" type="text" maxlength="25" class="input size2 W200" placeholder="按客户UID、姓名和手机号码" value="<?php echo $Skey2; ?>">　
        <input placeholder="起始日期" name="sDATE1" id="sDATE1" type="text"  class="input size2 W100" value="<?php echo (empty($sDATE1))?'':$sDATE1; ?>" size="10" maxlength="10" autocomplete="off">
        <b>～</b> 
        <input placeholder="结束日期" name="sDATE2" id="sDATE2" type="text"  class="input size2 W100" value="<?php echo (empty($sDATE2))?'':$sDATE2; ?>" size="10" maxlength="10" autocomplete="off">　
      <script>nulltext = '通话状态';zeai_cn__CreateFormItem('select','qxflag','<?php echo $qxflag; ?>','class="size2 picmiddle"',[{i:"1",v:"空号错号"},{i:"2",v:"无人接听"},{i:"3",v:"客户拒接"},{i:"4",v:"成功接通"},{i:"5",v:"其它"}]);</script>　
      <button type="submit" class="btn size2 QING"><i class="ico">&#xe6c4;</i> 筛选</button>
        <input type="hidden" name="p" value="<?php echo $p;?>" />
        <input type="hidden" name="k" value="<?php echo $k;?>" />
    </form>   
  </div>
    <!---->
	<?php
    if ($total <= 0 ) { ?>
  <div class='nodataico'><i></i><?php echo $tip_bt;?>暂无外呼记录
        <br><a href='javascript:void(0);' class='aQINGed' onClick="zeai.iframe('添加外呼记录','crm_talk_gj.php?submitok=add',700,430)">新增外呼记录</a>
        </div>
        <?php
    } else {
        $page_skin=2;$pagemode=3;$pagesize=$_ADM['admPageSize'];require_once ZEAI.'sub/page.php';?>
        <table class="tablelist">
        <form id="www_zeai_cn_FORM" method="get" action="<?php echo SELF; ?>">
        <tr>
        <th width="30"><input type="checkbox" id="checkboxall1" class="checkskin checkboxall"><label for="checkboxall1" class="checkskin-label"><i class="i1"></i></label></th>
        <th width="65" align="center">头像</th>
        <th width="120" align="left">UID/昵称/姓名</th>
        <th width="130" align="center">拔打时间</th>
        <th width="130" align="center">电话</th>
        <th width="100" align="left">呼出状态</th>
        <th width="130" align="left">通话时长</th>
        <th>备注</th>
        <th width="160" align="center">红娘信息</th>
        <th width="70" align="center">操作</th>
        <th width="11" align="center">&nbsp;</th>
        </tr>
        <?php
        for($i=1;$i<=$pagesize;$i++) {
            $rows = $db->fetch_array($rt,'name');
            if(!$rows) break;
            $id = $rows['id'];
			$admid = $rows['admid'];
			$uid = intval($rows['uid']);
            $admname = dataIO($rows['admname'],'out');			
            $name = dataIO($rows['name'],'out');
            $mob     = $rows['mob'];			
            $flag   = $rows['flag'];
            $talktime      = intval($rows['talktime']);
            $talknum    = $rows['talknum']; 
            $bz = dataIO($rows['talkbz'],'out');
			$addtime = $rows['addtime'];
			if($rows['talktime']>0){
				$wh_h=floor($rows['talktime']/3600);	
				$wh_i=floor(($rows['talktime']-$wh_h*3600)/60);	
				$wh_s=$rows['talktime']-$wh_h*3600-$wh_i*60;	
			}
			$time_str='';
			if($wh_h>0){$time_str.=$wh_h.'时';}
			if($wh_i>0 || $wh_h>0){$time_str.=$wh_i.'分';}
			if($wh_s>0 || $wh_i>0 || $wh_h>0){$time_str.=$wh_s.'秒';}
			
			$row = $db->ROW(__TBL_USER__,"sex,grade,photo_s,nickname","id=".$uid,"name");
			if ($row){
				$photo_s = $row['photo_s'];$sex= $row['sex'];$grade= $row['grade'];
				$photo_s_url = (!empty($photo_s))?UP.$photo_s:RES.'photo_s'.$sex.'.png';
				$nickname = trimhtml(dataIO($row['nickname'],'out'));
				$nickname_str = (!empty($nickname))?'<br>'.$nickname:'';
			}
        ?>
        <tr id="tr<?php echo $id;?>">
            <td width="30" height="60"><input type="checkbox" name="list[]" value="<?php echo $id; ?>" uid="<?php echo $uid; ?>" id="id<?php echo $id; ?>" class="checkskin"><label for="id<?php echo $id; ?>" class="checkskin-label"><i class="i1"></i></label>
            </td>
          <td width="65" align="left" class="lineH150"><a href="<?php echo Href('crm_u',$uid);?>&iframenav=1"><img src="<?php echo $photo_s_url; ?>" class="photo_s"></a></td>
          <td width="120" align="left" class="lineH150">
		  <a href="<?php echo Href('crm_u',$uid);?>&iframenav=1"><?php echo uicon($sex.$grade);?><?php echo $uid;?>
		  <?php echo "<font class='uleft'>".$nickname."</font>";?><font class='uleft'><?php echo $name;?></font></a>
          
          
          </td>
          <td width="130" height="60" align="center" class=" C666"><?php echo $addtime;?></td>
          <td width="130" height="60" align="center" class="lineH200 C666"><?php echo $mob;?></td>
          <td width="100" align="left"><?php switch($flag){case 1:echo '空号错号';break;case 2:echo '无人接听';break;case 3:echo '客户拒接';break;case 4:echo '成功接通';break;case 5:echo '其它';break;}?></td>
          <td width="130" align="left" class="lineH150"><?php if($flag==4){ echo $time_str;}else{ echo '--';}?>    
            </td>
            <td class="padding10"><?php echo $bz;?></td>
            <td width="160" height="60" align="center" class="lineH200 C666"><?php echo $admname.'(ID:'.$admid.')';?></td>
            <td width="70" align="center" ><?php if(CRMQX('crm_talk_gj_mod')){?>
            <a class="editbtn flag" flag="2" qxid="<?php echo $id;?>" title2="修改" title="修改"></a><?php }?>
            </td>
            <td width="11" align="center" >&nbsp;</td>
          </tr>
        <?php } ?>
        </form>
    </table>
    <?php }?>
    <!---->
</div>
<?php if ($total > 0 ) {?>
<div class="listbottombox">
    <input type="checkbox" id="checkboxall2" class="checkskin checkboxall"><label for="checkboxall2" class="checkskin-label"><i class="i1"></i></label>　
    <?php if(CRMQX('crm_talk_gj_del')){?><button type="button" id="btndellist" class="btn size2 HEI2 disabled action"><i class="ico">&#xe779;</i> 批量删除</button><?php }?>
    <input type="hidden" name="submitok" id="submitok" value="" />
    <?php echo '<div class="pagebox FR">'.$pagelist.'</div>'; ?>
</div>
<script>
var bg = '<?php echo $_Style['list_bg']; ?>',overbg = '<?php echo $_Style['list_overbg']; ?>',selectbg = '<?php echo $_Style['list_selectbg']; ?>';
zeai.listEach('.flag',function(obj){
	if(!obj.hasClass('disabled'))obj.onclick = function(){
		var id = parseInt(obj.getAttribute("qxid")),
		title2 = obj.getAttribute("title2");
		str = '<b class="S16">确定要修改记录？</b><br>外呼信息有变化 ，可以更新相关信息或添加备注信息！';
		//zeai.confirm(str,function(){
			zeai.iframe('修改外呼信息','crm_talk_gj.php?submitok=mod&id='+id,700,430);
		//});
		return false;
	}
});
<?php if(CRMQX('crm_talk_gj_del')){?>
o('btndellist').onclick = function() {
	allList({
		btnobj:this,
		url:'crm_talk_gj'+zeai.ajxext+'submitok=alldel',
		title:'批量删除',
		msg:'正在删除中...',
		ifjson:true,
		ifconfirm:true
	});	
}
<?php }?>
</script>
<script src="js/zeai_tablelist.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php }?>
<script src="laydate/laydate.js"></script><script>lay('#version').html('-v'+ laydate.v);
laydate.render({elem: '#sDATE1'});
laydate.render({elem: '#sDATE2'});
</script>
<?php require_once 'bottomadm.php';?>